<template>
  <div class="aside">
    <el-menu @select="menuClick">
      <el-menu-item index="add">
        新增
      </el-menu-item>
      <el-menu-item index="edit">
        修改
      </el-menu-item>
      <el-menu-item index="delete">
        删除
      </el-menu-item>
    </el-menu>
  </div>
</template>
<script>
import Mixin from '@/assets/mixin'
export default {
  name: 'Aside',
  mixins: [Mixin],
  doNotInit: true,
  data() {
    return {
      treeProps: {
        label: 'name',
        children: 'childs',
        isLeaf: 'leaf'
      },
      contextMenu: {
        display: 'none',
        x: '0px',
        y: '0px'
      }
    }
  },
  methods: {
    init() {
      if (process.client) {
        document.onclick = () => {
          this.contextMenu.display = 'none'
        }
      }
      this.toRouter('/cube/define/cubeDb')
    },
    loadTreeNode(node, resolve) {
      /* if (node.level === 0) {
        return resolve([{ id: -1, name: '数据仓库' }])
      } */
      if (node.level === 0) {
        this.ajaxGet({
          url: '/v3/cube/cubeDb',
          callback: data => {
            return resolve([
              { id: -1, name: '数据仓库', leaf: false, childs: data.rows }
            ])
          }
        })
        return
      }
      if (node.level === 1) {
        return resolve(node.data.childs)
      }
      if (node.level === 2) {
        this.ajaxGet({
          url: '/v3/cube/cubeModel',
          params: { dbId: node.id },
          callback: data => {
            return resolve(data.rows || [])
          }
        })
      }
      if (node.level === 3) {
        this.ajaxGet({
          url: '/v3/cube/cubeModelColumn',
          params: { tabId: node.id },
          callback: data => {
            return resolve(data.rows)
          }
        })
      }
    },
    nodeClick(data, node, el) {
      console.log(data)
      console.log(node)
      console.log(el)
    },
    nodeContextClick(event, data, node, el) {
      // this.contextMenu.display = 'block'
      // this.contextMenu.x = event.offsetX + 'px'
      // this.contextMenu.y = event.offsetY + 50 + 'px'
    },
    menuClick(index) {
      console.log(index)
    }
  }
}
</script>
